package com.itheima;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.FoodSetting;
import com.itheima.pojo.OrderSetting;
import com.itheima.utils.POIUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/repository")
public class RepositoryController{
    @Reference
    private RepositService repositService;
    @RequestMapping("/getfoodbank")
    public Result getfoodbank(@RequestParam("excelFile") MultipartFile excelFile){
        try {
            //1.POI解析模板文件
            List<String[]> list = POIUtils.readExcel(excelFile);
            //把数据封装OrderSetting
            List<FoodSetting> data = new ArrayList<>();
            for (String[] strings : list) {
                String name = strings[0];
                String state = strings[1];
                String size= strings[2];
                String age = strings[3];
                //日期与预约数量转换
               FoodSetting foodSetting = new FoodSetting(name,state,size,age);
                data.add(foodSetting);
            }
            //2.通过dubbo远程调用服务实现 POI解析模板文件数据->批量导入到数据库
           //repositService.add(data);
            return new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            //文件解析失败
            return new Result(false, MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }
    }
    }
